# 导入包
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
# 获取浏览器驱动
driver = webdriver.Firefox()
driver.maximize_window()
# 打开测试的页面
url = 'file:///root/NSD2408/html/register.html'
driver.get(url)

size = driver.find_element(By.CSS_SELECTOR, '#user').size
# {'height': 31.0, 'width': 192.0}
# 1.获取元素的大小
print('元素大小：', size['width'], size['height'])
# 2.获取元素文本
text = driver.find_element(By.CSS_SELECTOR, 'a').text
print('文本：', text)
# 3.获取元素的属性
a = driver.find_element(By.CSS_SELECTOR, 'a')
print('链接地址：', a.get_attribute('href'))
print('id:', a.get_attribute('id'))
print('链接打开方式：', a.get_attribute('target'))
# 4.判断元素是否可见
display = driver.find_element(By.CSS_SELECTOR, 'span').is_displayed()
print('元素是否可见：', display)
# 5.判断元素是否可用
enable = driver.find_element(By.CSS_SELECTOR, '#cancel').is_enabled()
print('元素是否可用：', enable)
# 6.判断元素是否选中
qc = driver.find_element(By.CSS_SELECTOR, '#qc')
qc.click()
checked = qc.is_selected()
print('是否选中：', checked)

# 关闭浏览器
sleep(3)
driver.quit()